package service;

import dao.EquipmentMap;
import model.ConnectHandlerLineModel;
import org.apache.ibatis.session.SqlSession;

public class ConnectHandlerTask<T> implements Runnable {
    private T[] data;
    private Class<T> tClass;
    private SqlSession sqlSession;

    public ConnectHandlerTask(SqlSession sqlSession, T[] data, Class<T> tClass) {
        this.data = data;
        this.tClass = tClass;
        this.sqlSession = sqlSession;
    }

    @Override
    public void run() {
        EquipmentMap equipmentMap = sqlSession.getMapper(EquipmentMap.class);
        final String name = tClass.getName();
        switch (name) {
            case "model.ConnectHandlerLineModel":
                ConnectHandlerLineModel[] connectHandlerLineModels = (ConnectHandlerLineModel[]) data;
                for (ConnectHandlerLineModel connectHandlerLineModel :
                        connectHandlerLineModels) {
                    equipmentMap.insertIntoConnectHandler(connectHandlerLineModel);
                }
                sqlSession.commit();
                break;
            default:
                break;
        }
    }
}
